package controllayer;

import modellayer.Customer;
import modellayer.Item;
import modellayer.Order;
import modellayer.Salesman;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The Class TrackingControllerTest.
 *@author Benjamin Ørskov
 *@author Lasse Lambertsen
 *@author Ole Kirk
 *@author Søren Søgaard
 */
public class TrackingControllerTest {
	/** The order co1. */
	controllayer.OrderController orderCo1 = new controllayer.OrderController();

	/** The person co1. */
	controllayer.PersonController personCo1 = new controllayer.PersonController();

	/** The item co1. */
	controllayer.ItemController itemCo1 = new controllayer.ItemController();

	/** The tacking to1. */
	controllayer.TrackingController trackingCo1 = new controllayer.TrackingController();

	/** The salesman counter. */
	private int salesmanCounter = 0;

	/** The order counter. */
	private static int orderCounter = 1;

	/**
	 * Sets the up.
	 *
	 * @throws Exception
	 *             the exception
	 */
	@Before
	public void setUp() throws Exception {
		personCo1.createCustomer("Ole", "Vesterbro", "Aalborg",
				"olex999@live.dk", "123");
		personCo1.createSalesman("Benja", "Eternitten", "AA",
				"leckcy@gmail.com", "456", 1.0);
		personCo1.createSalesman("Søren", "Eternitten", "AA",
				"leckcy@gmail.com", "456", 1.0);
		personCo1.createSalesman("John", "Eternitten", "AA",
				"leckcy@gmail.com", "456", 1.0);
		personCo1.createSalesman("Kaj", "Eternitten", "AA", "leckcy@gmail.com",
				"456", 1.0);
		personCo1.createSalesman("Andrea", "Eternitten", "AA",
				"leckcy@gmail.com", "456", 1.0);
		itemCo1.createItem("Skrue", 1, 10.0, 1000);
		itemCo1.createItem("Skruetrækker", 2, 100.0, 100);
		salesmanCounter = personCo1.getSalesmanID();

		Order o = orderCo1.createOrder();
		Customer c = (Customer) personCo1.findCustomer("123");
		o.setCustomer(c);
		Salesman s = (Salesman) personCo1.findSalesman(salesmanCounter - 1);
		o.setSalesman(s);
		Item i = itemCo1.findItem(1);
		orderCo1.addItem(i, 25, o);
		o.getSalesman().setRevenue(o.getSalesman().getRevenue() + o.getPrice());

		Order o1 = orderCo1.createOrder();
		Customer c1 = (Customer) personCo1.findCustomer("123");
		o1.setCustomer(c1);
		Salesman s1 = (Salesman) personCo1.findSalesman(salesmanCounter - 2);
		o1.setSalesman(s1);
		Item i1 = itemCo1.findItem(1);
		orderCo1.addItem(i1, 10, o1);
		o1.getSalesman().setRevenue(
				o1.getSalesman().getRevenue() + o1.getPrice());

		Order o2 = orderCo1.createOrder();
		Customer c2 = (Customer) personCo1.findCustomer("123");
		o2.setCustomer(c2);
		Salesman s2 = (Salesman) personCo1.findSalesman(salesmanCounter - 3);
		o2.setSalesman(s2);
		Item i2 = itemCo1.findItem(1);
		orderCo1.addItem(i2, 199, o2);
		o2.getSalesman().setRevenue(
				o2.getSalesman().getRevenue() + o2.getPrice());

		Order o3 = orderCo1.createOrder();
		Customer c3 = (Customer) personCo1.findCustomer("123");
		o3.setCustomer(c3);
		Salesman s3 = (Salesman) personCo1.findSalesman(salesmanCounter - 4);
		o3.setSalesman(s3);
		Item i3 = itemCo1.findItem(1);
		orderCo1.addItem(i3, 5, o3);
		o3.getSalesman().setRevenue(
				o3.getSalesman().getRevenue() + o3.getPrice());

		Order o4 = orderCo1.createOrder();
		Customer c4 = (Customer) personCo1.findCustomer("123");
		o4.setCustomer(c4);
		Salesman s4 = (Salesman) personCo1.findSalesman(salesmanCounter - 5);
		o4.setSalesman(s4);
		Item i4 = itemCo1.findItem(1);
		orderCo1.addItem(i4, 57, o4);
		o4.getSalesman().setRevenue(
				o4.getSalesman().getRevenue() + o4.getPrice());
	}

	/**
	 * Tear down.
	 *
	 * @throws Exception
	 *             the exception
	 */
	@After
	public void tearDown() throws Exception {
		personCo1.getPersonArray().clear();
	}

	/**
	 * Test method for
	 * {@link controllayer.TrackingController#getSortedSalesmanArray()}.
	 */
	@Test
	public void testGetSortedSalesmanArray() {
		System.out.println(trackingCo1.getSortedSalesmanArray());
	}

}
